package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.VO.CartVO;
import com.example.demo.bean.Cart;
import com.example.demo.bean.User;
import com.example.demo.mapper.CartMapper;
import com.example.demo.service.ICartService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *   服务实现类
 * </p>
 *
 * @author 京平笙
 * @since 2021-12-06
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {
    @Resource
    private CartMapper cartMapper;
//    @Override
//    public List<CartVO> showUserCart(Integer uid) {
//        return cartMapper.showUserCart(uid);
//    }


//    @Override
//    public List<CartVO> showUserCart(User user) {
////        service
////        设置 page √
////        设置排序 √
//        Page<CartVO> page = new Page<>();
//        QueryWrapper<CartVO> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("u.id",user.getId()).eq("c.is_delete",0).orderByAsc("c.total");
//        List<CartVO> cartVOS = cartMapper.selectUserCart(page,queryWrapper);
//        return cartVOS;
//    }

    @Override
    @ResponseBody
    public IPage<CartVO> showUserCart( Page<CartVO> voPage,QueryWrapper<CartVO> listQueryWrapper) {
//  查询用户有多少购物车买单属于他的 select *  from cart where uid=1
        IPage<CartVO> cartVOIPage = cartMapper.showUserCart(voPage, listQueryWrapper);
        System.out.println("----------------------------------------");
//        每页几条数据
        System.out.println(cartVOIPage.getSize());
//        有多少页
        System.out.println(cartVOIPage.getPages());
//        当前第几页
        System.out.println(cartVOIPage.getCurrent());
//        一共几条数据
        System.out.println(cartVOIPage.getTotal());
        System.out.println("----------------------------------------");
        return cartVOIPage;
    }

    
}
